/**
 * <p>
 * Title: Human.java
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: Copyright (c) 2009
 * </p>
 * <p>
 * Company: xunjie
 * </p>
 * 
 * @author shenhao
 * @date 2010-3-8
 * @version 1.0
 */
package cn.haona.game.simb.object.bio;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import cn.haona.db.RelevanceBean;
import cn.haona.game.simb.object.BioImpl;
import cn.haona.reflect.ReflectionBasic;

/**
 * <p>
 * Title: Human
 * </p>
 * <p>
 * Description: 人类
 * </p>
 * <p>
 * Company: xunjie
 * </p>
 * 
 * @author shenhao
 * @date 2010-3-8
 */
public abstract class Human extends BioImpl implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2482029010075455749L;

	// 人的类型
	final public static int HUMAN_TYPE_USER = 0;// 用户
	final public static int HUMAN_TYPE_NPC = 1;// NPC

	// 职业
	// 低级马仔
	final public static int JOB_ROGUE_LEVEL_0 = 0;
	// 中级混混
	final public static int JOB_ROGUE_LEVEL_1 = 1;
	// 高级流氓
	final public static int JOB_ROGUE_LEVEL_2 = 2;
	// 警员
	final public static int JOB_POLICE_LEVEL_0 = 3;
	// 警长
	final public static int JOB_POLICE_LEVEL_1 = 4;
	// 职业保镖
	final public static int JOB_BODYGUARD_LEVEL_0 = 5;
	// 武警
	final public static int JOB_FORCE_POLICE_LEVEL_0 = 6;
	// 地产商
	final public static int JOB_ESTATE_LEVEL_0 = 7;
	// 腐败官员
	final public static int JOB_DIRTY_OFFICER_0 = 8;

	// 百姓
	final public static int JOB_CITIZEN_0 = 100;

	public PersistenceHuman getHumanPO() {
		if (pO != null) {
			return (PersistenceHuman) pO;
		}
		return null;
	}

	public static void copyParams(PersistenceHuman humanOrg,
			PersistenceHuman humanCopyer) {
		// human所需反射的参数
		HashMap<String, RelevanceBean> reflectRelevance = new HashMap<String, RelevanceBean>();
		PersistenceHuman ph = new PersistenceHuman() {
			public void initMe() {
				setReflectRelevance(reflectRelevance);
			}
		};
		reflectRelevance = ph.getReflectRelevance();

		// 得到反射关联迭代器
		Iterator iterRR = reflectRelevance.entrySet().iterator();
		try {
			// 迭代
			while (iterRR.hasNext()) {
				Map.Entry entry = (Map.Entry) iterRR.next();
				String key = (String) entry.getKey();
				RelevanceBean rBean = (RelevanceBean) entry.getValue();
				// 得到数据库字段所对应的值
				// 如果不是主键
				if (!rBean.isPrimary) {
					String paramName = rBean.getParamName();
					// 改变参数首字母为大写
					String paramNameSet = "set"
							+ ReflectionBasic.changeHeadLetterUpper(paramName);
					String paramNameGet = "get"
							+ ReflectionBasic.changeHeadLetterUpper(paramName);
					// 得到原对象的值
					Object paramValue;

					paramValue = ReflectionBasic.invokeMethod(humanOrg,
							paramNameGet, null);
					//如果有值
					if (paramValue != null) {
						// 设置复制对象的值
						ReflectionBasic.invokeMethod(humanCopyer, paramNameSet,
								new Object[] { paramValue });
					}//end if(如果有值)
				}//end if(如果不是主键)
			}// end while(迭代)
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
